package mock.bo;

import mock.dao.AccountDAO;
import mock.dao.AccountDAOImp;
import mock.dao.CardDAO;
import mock.dao.CardDAOImp;
import mock.dao.CashTransferDAO;
import mock.dao.CashTransferDAOImp;
import mock.dao.CustomerDAO;
import mock.dao.CustomerDAOImp;
import mock.dto.AccountDTO;
import mock.dto.CardDTO;
import mock.dto.CustomerDTO;

public class CashTransferImp implements CashTransfer{
	
	private AccountDAO accountDAO = new AccountDAOImp();
	private CustomerDAO customerDAO = new CustomerDAOImp();
	private CashTransferDAO cashTransferDAO = new CashTransferDAOImp();
	
	/**
	 * lay thong tin nguoi gui tien
	 */
	@Override
	public AccountDTO getAccountInformation(String cardNo) {
		// TODO Auto-generated method stub
		AccountDTO account = accountDAO.getAccountByCardNo(cardNo);
		return account;
	}
	
	/**
	 * lay thong tin nguoi chuyen tien
	 */
	@Override
	public CustomerDTO getCustomerInformation(String cardNo) {
		// TODO Auto-generated method stub
		return customerDAO.getCustomerByCardNo(cardNo);
	}
	
	/**
	 * lay thong tin nguoi nhan tien
	 */
	@Override
	public CustomerDTO getReceiverCustomerInformation(int accountID) {
		// TODO Auto-generated method stub
		return customerDAO.getCustomerByAccountID(accountID);
	}
	
	/**
	 * thuc hien viec chuyen tien
	 */
	@Override
	public boolean processCashTransfer(int transferAccountID, int receiverAccountID, double amount) {
		// TODO Auto-generated method stub
		AccountDTO transferAccount = accountDAO.getAccountByAccountID(transferAccountID);
		AccountDTO receiverAccount = accountDAO.getAccountByAccountID(receiverAccountID);
		double newTransferAmount = transferAccount.getBalance() - amount;
		double newReceiverAmount = receiverAccount.getBalance() + amount;
		return cashTransferDAO.cashTransfer(transferAccountID, receiverAccountID, newTransferAmount, newReceiverAmount);
	}
	
	
	
}
